def check_2(n):
    while n > 0:
        save_2.append(n % 2)
        n //= 2
    return save_2

def check_8(n):
    while n > 0:
        save_8.append(n % 8)
        n //= 8
    return save_8

ans = []
for i in range(1, 100000000):
    save_2 = []
    save_8 = []
    if sum(check_2(i)) == sum(check_8(i)):
        ans.append(i)
        if len(ans) == 23:
            print(ans[-1])
            break